from datetime import timezone
import time
from django.conf import settings
from .models import Payment

def process_payment(payment):
    """模拟支付处理流程"""
    # 生成交易号
    payment.transaction_id = f"TX{int(time.time())}{payment.id}"
    payment.save()
    
    # 实际项目中这里会调用第三方支付API
    # 模拟支付成功
    payment.status = 'paid'
    payment.paid_at = timezone.now()
    payment.save()
    
    # 更新订单状态
    payment.order.status = 'confirmed'
    payment.order.save()